import { GameConst } from "../../../../../component/gconst/GameConst";
import { GTextFormat } from "../../../../../common/GTextFormat";
import { FontUtil } from "../../../../../common/font/FontUtil";
import { ObjCreate } from "../../../common/ObjCreate";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { BaseItem } from "../../../common/BaseItem";
import { Language } from "../../../../../../extend/language/Language";
import { MoneyItem } from "../../../common/item/MoneyItem";
import { GlobalClass } from "../../../../../../com/mui/core/GlobalClass";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { GNumericStepper } from "../../../../../../com/mui/controls/GNumericStepper";
import { ResouceConst } from "../../../../../component/gconst/ResouceConst";
import { EPrictUnit } from "../../../../../../Message/Public/EPrictUnit";
import { ItemConfig } from "../../../../resource/ItemConfig";
import { ItemData } from "../../../../resource/info/ItemData";
import { ItemInfo } from "../../../../resource/info/ItemInfo";
import { ShopConfig } from "../../../../resource/ShopConfig";
import { ECategory } from "../../../../../../Message/Public/ECategory";
import { EProp } from "../../../../../../Message/Public/EProp";
import { Cache } from "../../../../cache/Cache";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { SkillRuneEvent } from "../SkillRuneEvent";
import { FilterConst } from "../../../../../component/gconst/FilterConst";
import { GCheckBox } from "../../../../../../com/mui/controls/GCheckBox";
import { GButton } from "../../../../../../com/mui/controls/GButton";
import { ShopItemInfo } from "../../../../resource/info/ShopItemInfo";
type int = number;
//class RuneFeedMaterialCell
    
    export  class RuneFeedMaterialCell /* flash.display.Sprite */
    {
        constructor(arg1: int)
        {
            
            this._itemLevel = arg1;
            if (this._itemLevel != 1) 
            {
                this._coinCostBase = GameConst.RuneFeedFee2;
            }
            else 
            {
                this._coinCostBase = GameConst.RuneFeedFee1;
            }
            this.mouseEnabled = false;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=new GTextFormat(FontUtil.songtiName, 12, 15788607);
            loc1.indent = 7;
            ObjCreate.createSpBannerAndBg(0, 0, 142, 168, this.getTitle(), this, loc1);
            ObjCreate.createBitmap(ImagesConst.PackItemBg, 18, 34, this);
            this._item = new BaseItem();
            ObjCreate.setObjAttri(this._item, 21, 37, 32, 32, this);
            ObjCreate.createTextField(Language.getString(44073), 60, 36, 30, 20, this);
            this._moneyItem = new MoneyItem();
            this._moneyItem.mouseEnabled = false;
            this._moneyItem.mouseChildren = false;
            ObjCreate.setObjAttri(this._moneyItem, 30, 36, -1, -1, this);
            var loc2=GlobalClass.getBitmap(ImagesConst.Friend_over);
            ObjCreate.setObjAttri(loc2, 58, 52, 70, 17, this);
            this._effectText = ObjCreate.createTextField(Language.getStringByParam(44007, "10"), 60, 53, 60, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createTextField(Language.getString(44008), 15, 83, 60, 20, this);
            this._numStepper = new GNumericStepper();
            this._numStepper.setSize(49, 22);
            this._numStepper.move(70, 80);
            this._numStepper.styleName = "NumericStepper";
            this._numStepper.drawNow();
            this._numStepper.textField.setStyle("upSkin", ResouceConst.getScaleBitmap("DisabledBg"));
            this._numStepper.textField.drawNow();
            this._numStepper.maximum = 99;
            this._numStepper.minimum = 1;
            this.addChild(this._numStepper);
            this._btnFeed = ObjCreate.createGButton(Language.getString(44009), 49, 110, 48, 22, this, "ButtonRedMini");
            ObjCreate.createTextField(Language.getString(44010), 15, 143, 40, 20, this);
            ObjCreate.createBg(51, 143, 77, 18, this, "DisabledBg");
            this._coinMoneyItem = new MoneyItem();
            this._coinMoneyItem.mouseEnabled = false;
            this._coinMoneyItem.mouseChildren = false;
            this._coinMoneyItem.update(this._coinCostBase, EPrictUnit._EPriceUnitCoin);
            ObjCreate.setObjAttri(this._coinMoneyItem, 28, 143, -1, -1, this);
            this.getData();
            this.updateView();
            this.addListeners();
            return;
        }

        /* internal  */getData(): void
        {
            var loc2=0;
            var loc1=ItemConfig.instance.getItemsByJudge(this.isRuneFeedMaterial);
            if (loc1.length > 0) 
            {
                loc2 = 0;
                while (loc2 < loc1.length) 
                {
                    this._itemData = new ItemData((loc1[loc2] as ItemInfo).item.code);
                    this._shopInfo = ShopConfig.instance.getShopItemInfoByCode(this._itemData.itemCode);
                    if (!this._shopInfo) 
                    {
                    };
                    ++loc2;
                }
            }
            return;
        }

        /* internal  */isRuneFeedMaterial(arg1: ItemInfo): Boolean
        {
            if (arg1.item.category == ECategory._ECategoryProp && arg1.item.type == EProp._EPropRuneGrowth && arg1.item.itemLevel == this._itemLevel) 
            {
                return true;
            }
            return false;
        }

        /* internal  */updateView(): void
        {
            if (this._itemData) 
            {
                this._item.itemData = this._itemData;
                this._effectText.htmlText = Language.getStringByParam(44007, this._itemData.itemInfo.item.effect.toString());
            }
            if (this._shopInfo) 
            {
                this._moneyItem.update(this._shopInfo.tshopSell.price, this._shopInfo.unit);
            }
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnFeed.addEventListener(flash.events.MouseEvent.CLICK, this.onFeedClick);
            this._numStepper.addEventListener(flash.events.Event.CHANGE, this.onNumChange);
            return;
        }

        /* internal  */onFeedClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=Cache.instance.role.money;
            if (loc1.coin + loc1.coinBind < this._numStepper.value * this._coinCostBase) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin));
            }
            if (this._itemData) 
            {
                this.dispatchEvent(new SkillRuneEvent(SkillRuneEvent.RuneFeedClick));
            }
            return;
        }

        /* internal  */onNumChange(arg1: Object /* flash.events.Event */): void
        {
            this._coinMoneyItem.update(this._numStepper.value * this._coinCostBase, EPrictUnit._EPriceUnitCoin);
            return;
        }

        /* internal  */getTitle(): string
        {
            if (this._itemLevel == 1) 
            {
                return Language.getString(44011);
            }
            return Language.getString(44012);
        }

        public get isAutoBuy(): Boolean
        {
            return false;
        }

        public get materialLevel(): int
        {
            return this._itemLevel;
        }

        public get materalNum(): int
        {
            return int(this._numStepper.value);
        }

        public set currentNum(arg1: int)
        {
            if (this._item) 
            {
                this._item.amount = arg1;
            }
            if (arg1 != 0) 
            {
                this._item.filters = [];
            }
            else 
            {
                this._item.filters = [FilterConst.colorFilter];
            }
            return;
        }

        /* internal */ /* var */_itemLevel: int;

        /* internal */ /* var */_item: BaseItem;

        /* internal */ /* var */_moneyItem: MoneyItem;

        /* internal */ /* var */_effectText: Object /* flash.text.TextField */;

        /* internal */ /* var */_cbAutoByMaterial: GCheckBox;

        /* internal */ /* var */_numStepper: GNumericStepper;

        /* internal */ /* var */_btnFeed: GButton;

        /* internal */ /* var */_coinMoneyItem: MoneyItem;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_shopInfo: ShopItemInfo;

        /* internal */ /* var */_coinCostBase: int=500;
    }
